-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Portafly: Adding reacti18next #1784
Portafly: Adding reacti18next #1784
Conversation
e96b235
to
e84394c
Compare
e84394c
to
035459c
Compare
Comparing react-i18next with polyglot (see #1776, #1783)
Resuming: |
I am 80% in favor of using Polyglot, mainly because it's simpler, smaller and hence easier to handle. As for the aforementioned features:
|
About the hook, we can define it now and later we can forget about it, is not my main concern. But think about the formatting, because this is going to be a daily need. String in our json file:
And then use it in our components:
It will be rendered as plain text by polyglot:
Then, to parse it as HTML we need to use another lib like
Or, if we don't want to use Also think what happens if we need to render jsx (e.g a link) in the text. react-i18next supports it, polyglot not. Polyglot option is not so simple after all. |
It is worth pointing out how formatting would look like using the different libraries. Welcome to *PaternFly*! The best app ever
Docs team has to insert interpolation objects they don't understand and can't use full sentences.
Docs team has to insert weird html-like elements that they also wouldn't understand.
Docs would need to use common HTML formatting tags. You have 5 new messages. Mark all as read.
Interpolation gets more complex and Docs cannot handle links directly.
This doesn't look so bad, still Doc team cannot handle links, needs to use weird html-link tags.. and it seems like it doesn't support interval plurals (i.e. count: 0).
Need to use My conclusion is it isn't worth it to use a complex library such as i18next. I'm not sure at all it's going to pay off learning to use it and all the headaches we're going to have. If the only problem is docs team not wanting to use HTML in the phrases I think we should still go for Polyglot. While doing this small experiment I spend 1 min tops writing translations for Polyglot, the rest of the hours was trying to figure out how to use i18next. Maybe it doesn't have rich features or we have to craft some small parses/functions ourselves but I don't think that's a problem at all. |
e3faa98
to
cab40ee
Compare
@josemigallas @didierofrivia |
portafly/src/i18n/i18n.tsx
Outdated
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i'] | ||
}, | ||
resources: { | ||
en: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to check it first but I think we can simplify this.
import * as Translations from 'i18n/locales'
const options = {
resources: Translations
}
In order to prevent repetition, too many imports and a very big resources property. Each locale should have its own "index" file such as i18n/locales/EN
, i18n/locales/JP
, etc. And then in i18n/index
we export an object with everything needed for options.resources
:
// i18n/locales/index.ts
import EN from 'i18n/locales/EN'
import JP from 'i18n/locales/JP'
export {
en: EN,
jp: JP
}
// i18n/i18n.tsx
import * as Translations from 'i18n/locales'
// ...
const options = {
// ...
resources: Translations
}
portafly/src/i18n/i18n.tsx
Outdated
format: formatFn, | ||
escapeValue: false | ||
}, | ||
ns: ['shared', 'overview', 'analytics', 'applications', 'integration'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a type for the "sections". And be used here as well as in locales/index.ts.
portafly/src/i18n/i18n.tsx
Outdated
} | ||
|
||
const options = { | ||
lng: 'en', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally there would also be a type for languages, so that we can use it as keys for retrieving the translations, like in https://github.com/3scale/porta/pull/1783/files#diff-86aa4a15c591a31fa47c49447bc69228R10-R11:
export const TRANSLATIONS: Record<Locales.LOCALES, ITranslations> = {
[Locales.enUS]: enUsTranslations,
[Locales.jaJP]: jaJpTranslations
}
de1bced
to
3276742
Compare
3276742
to
d23ef52
Compare
adds some types and encapsulates translations files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
It was a good PR in the end! Congrats, good joint effort! 🎖 🎖 |
What this PR does / why we need it:
We need to choose a localization/internazionalization framework for portafly
This PR tests react-i18next
Pros:
useTranslation
hook<Trans />
component<Translation/>
componentwithTranslation
HOCt()
methodCons:
Requires more configuration, is more complex than polyglot
Which issue(s) this PR fixes
https://issues.redhat.com/browse/THREESCALE-4685 (parent)
https://issues.redhat.com/browse/THREESCALE-4687 (format of strings files)
https://issues.redhat.com/browse/THREESCALE-4688 (choosing library)
Verification steps